//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package org.springframework.security.oauth2.provider;

import java.io.Serializable;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import org.springframework.security.core.GrantedAuthority;

public class OAuth2Request extends BaseRequest implements Serializable {
    private static final long serialVersionUID = 1L;
    private Set<String> resourceIds;
    private Collection<? extends GrantedAuthority> authorities;
    private boolean approved;
    private TokenRequest refresh;
    private String redirectUri;
    private Set<String> responseTypes;
    private Map<String, Serializable> extensions;

    public OAuth2Request(Map<String, String> requestParameters, String clientId, Collection<? extends GrantedAuthority> authorities, boolean approved, Set<String> scope, Set<String> resourceIds, String redirectUri, Set<String> responseTypes, Map<String, Serializable> extensionProperties) {
        this.resourceIds = new HashSet();
        this.authorities = new HashSet();
        this.approved = false;
        this.refresh = null;
        this.responseTypes = new HashSet();
        this.extensions = new HashMap();
        this.setClientId(clientId);
        this.setRequestParameters(requestParameters);
        this.setScope(scope);
        if (resourceIds != null) {
            this.resourceIds = new HashSet(resourceIds);
        }

        if (authorities != null) {
            this.authorities = new HashSet(authorities);
        }

        this.approved = approved;
        if (responseTypes != null) {
            this.responseTypes = new HashSet(responseTypes);
        }

        this.redirectUri = redirectUri;
        if (extensionProperties != null) {
            this.extensions = extensionProperties;
        }

    }

    protected OAuth2Request(OAuth2Request other) {
        this(other.getRequestParameters(), other.getClientId(), other.getAuthorities(), other.isApproved(), other.getScope(), other.getResourceIds(), other.getRedirectUri(), other.getResponseTypes(), other.getExtensions());
    }

    protected OAuth2Request(String clientId) {
        this.resourceIds = new HashSet();
        this.authorities = new HashSet();
        this.approved = false;
        this.refresh = null;
        this.responseTypes = new HashSet();
        this.extensions = new HashMap();
        this.setClientId(clientId);
    }

    public OAuth2Request() {
        this.resourceIds = new HashSet();
        this.authorities = new HashSet();
        this.approved = false;
        this.refresh = null;
        this.responseTypes = new HashSet();
        this.extensions = new HashMap();
    }

    public String getRedirectUri() {
        return this.redirectUri;
    }

    public Set<String> getResponseTypes() {
        return this.responseTypes;
    }

    public Collection<? extends GrantedAuthority> getAuthorities() {
        return this.authorities;
    }

    public boolean isApproved() {
        return this.approved;
    }

    public Set<String> getResourceIds() {
        return this.resourceIds;
    }

    public Map<String, Serializable> getExtensions() {
        return this.extensions;
    }

    public OAuth2Request createOAuth2Request(Map<String, String> parameters) {
        return new OAuth2Request(parameters, this.getClientId(), this.authorities, this.approved, this.getScope(), this.resourceIds, this.redirectUri, this.responseTypes, this.extensions);
    }

    public OAuth2Request narrowScope(Set<String> scope) {
        OAuth2Request request = new OAuth2Request(this.getRequestParameters(), this.getClientId(), this.authorities, this.approved, scope, this.resourceIds, this.redirectUri, this.responseTypes, this.extensions);
        request.refresh = this.refresh;
        return request;
    }

    public OAuth2Request refresh(TokenRequest tokenRequest) {
        OAuth2Request request = new OAuth2Request(this.getRequestParameters(), this.getClientId(), this.authorities, this.approved, this.getScope(), this.resourceIds, this.redirectUri, this.responseTypes, this.extensions);
        request.refresh = tokenRequest;
        return request;
    }

    public boolean isRefresh() {
        return this.refresh != null;
    }

    public TokenRequest getRefreshTokenRequest() {
        return this.refresh;
    }

    public String getGrantType() {
        if (this.getRequestParameters().containsKey("grant_type")) {
            return (String)this.getRequestParameters().get("grant_type");
        } else {
            if (this.getRequestParameters().containsKey("response_type")) {
                String response = (String)this.getRequestParameters().get("response_type");
                if (response.contains("token")) {
                    return "implicit";
                }
            }

            return null;
        }
    }

    public int hashCode() {
        int result = super.hashCode();
        result = 31 * result + (this.approved ? 1231 : 1237);
        result = 31 * result + (this.authorities == null ? 0 : this.authorities.hashCode());
        result = 31 * result + (this.extensions == null ? 0 : this.extensions.hashCode());
        result = 31 * result + (this.redirectUri == null ? 0 : this.redirectUri.hashCode());
        result = 31 * result + (this.resourceIds == null ? 0 : this.resourceIds.hashCode());
        result = 31 * result + (this.responseTypes == null ? 0 : this.responseTypes.hashCode());
        return result;
    }

    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        } else if (!super.equals(obj)) {
            return false;
        } else if (this.getClass() != obj.getClass()) {
            return false;
        } else {
            OAuth2Request other = (OAuth2Request)obj;
            if (this.approved != other.approved) {
                return false;
            } else {
                if (this.authorities == null) {
                    if (other.authorities != null) {
                        return false;
                    }
                } else if (!this.authorities.equals(other.authorities)) {
                    return false;
                }

                if (this.extensions == null) {
                    if (other.extensions != null) {
                        return false;
                    }
                } else if (!this.extensions.equals(other.extensions)) {
                    return false;
                }

                if (this.redirectUri == null) {
                    if (other.redirectUri != null) {
                        return false;
                    }
                } else if (!this.redirectUri.equals(other.redirectUri)) {
                    return false;
                }

                if (this.resourceIds == null) {
                    if (other.resourceIds != null) {
                        return false;
                    }
                } else if (!this.resourceIds.equals(other.resourceIds)) {
                    return false;
                }

                if (this.responseTypes == null) {
                    if (other.responseTypes != null) {
                        return false;
                    }
                } else if (!this.responseTypes.equals(other.responseTypes)) {
                    return false;
                }

                return true;
            }
        }
    }
}
